# Maintainer: Sam Whited <sam@samwhited.com>
pkgname=jackal
pkgver=0.64.0
pkgrel=7
pkgdesc="Instant messaging server using XMPP"
url="https://github.com/ortuman/jackal"
arch="all"
license="Apache-2.0"
depends="gettext openssl"
makedepends="go"
install="jackal.pre-install jackal.post-install"
pkgusers="jackal"
pkggroups="jackal"
subpackages="$pkgname-openrc"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/ortuman/jackal/archive/refs/tags/v$pkgver.tar.gz
	jackal.initd
	jackal.logrotate
	init.sql
	config.yml.tmpl
	"
# !check: checks require unpackaged external tools
# net: fetch dependencies
options="!check net"

export GOPATH="$srcdir/go"
export GOCACHE="$srcdir/go-build"
export GOTEMPDIR="$srcdir/go"

prepare() {
	default_prepare

	go mod download
}

build() {
	go build ./cmd/jackal
	go build ./cmd/jackalctl
}

package() {
	install -d -o jackal -g jackal "$pkgdir"/etc/jackal
	install -d -m755 -o jackal -g jackal "$pkgdir"/var/lib/jackal
	install -D -m644 -o jackal -g jackal "$srcdir"/init.sql "$pkgdir"/var/lib/jackal/init.sql
	install -D -m644 -o jackal -g jackal sql/postgres.up.psql "$pkgdir"/var/lib/jackal/postgres.up.psql

	install -D -m755 jackal "$pkgdir"/usr/bin/jackal
	install -D -m755 jackalctl "$pkgdir"/usr/bin/jackalctl
	install -D -m755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -D -m644 "$srcdir"/config.yml.tmpl "$pkgdir"/etc/jackal/config.yml.tmpl
	install -D -m644 "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname
}

sha512sums="
40b4f489bd43ce64ea49bdc8b6f97483d9b159c85ed6a8b8d032b35befaa72b4cac6ee8235b2c4bead64c4e2025d03db53ff9bd2eace25ac1c5660a153c623b5  jackal-0.64.0.tar.gz
5e18714da66506d0ec6bacf051e9060b0e38976addff0aed8d9c8b553505a1fd637de2056aa91e3a46b486e8920c8a7d64990f0d497d35a74de02833bccf7f9f  jackal.initd
d38852e817665b1a408dba66de671e673dc11200142362127ef2f6e34489ca3ed7cdcd6bbd05ab876ba89015d64d30f14f1899a899dd92ccd6a000511930277c  jackal.logrotate
7c4220f2e92ef9230dadbc0dca3f75510f2abc368d57d938ff06e29042a1a284f257fd3bb94ac7fd35ffbef6cb31cbcb643a881e8f06f5802e912f7a92e143b2  init.sql
1a6ff8979ac80bd0e954cf44aec94ad2540d2151114418a97650b0835494e73a33c414664e52ca036f8e76f3c36eec7cf818b88ae64c59be1b7c0b752a52bc62  config.yml.tmpl
"
